﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WAF.Server;
using WAF.Server.Ipc;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace PerformanceTests
{
    class PerformanceTestWcf: PerformanceTestBase
    {
        public PerformanceTestWcf(bool useNamedPipes )
        {
            appServer = new AppServerService();
            

            Console.WriteLine("Create App Server Host");
            ServiceHost serviceBufferedTcpHost = null;
            try
            {
                Binding binding;
                Uri uri;

                if (useNamedPipes)
                {
                    uri = new Uri("net.pipe://localhost/2WAF/PerformanceTests");
                    NetNamedPipeBinding pipesBinding = new NetNamedPipeBinding();
                    pipesBinding.TransferMode = TransferMode.Buffered;
                    pipesBinding.Security.Mode = NetNamedPipeSecurityMode.None;
                    binding = pipesBinding;
                }
                else
                {
                    uri = new Uri("net.tcp://localhost/2WAF/PerformanceTests");
                    NetTcpBinding tcpBinding = new NetTcpBinding();
                    tcpBinding.TransferMode = TransferMode.Buffered;
                    tcpBinding.Security.Mode = SecurityMode.None;
                    binding = tcpBinding;
                }
                serviceBufferedTcpHost = new ServiceHost(appServer);
                serviceBufferedTcpHost.AddServiceEndpoint(typeof(IAppServerIpcContract), binding, uri);

                Console.WriteLine("Open App Server Host");
                serviceBufferedTcpHost.Open();

                Console.WriteLine("App Server Host is running");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to Create App Server Host");
                Console.WriteLine(e.ToString());
                Console.WriteLine();
            }

            webServer = new WebServerService(this, useNamedPipes);
        }

        public override void SendRequest(ContentRequest request)
        {
            base.SendRequest(request);
            webServer.ProcessNativeRequest(request, null);
        }



    }
}
